<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue3-escook</title>
  <link rel="stylesheet" href="./lib/style.css">
  <script type="importmap">
    {
      "imports" : {
        "vue": "./lib/vue-3.4.29.js"
      }
    }
  </script>
  <script type="module">
    import { createApp, ref } from 'vue'

    const app = createApp({
      setup() {
        // const getFocus = () => {
        //   document.querySelector('input')?.focus()
        // }

        // 注意：如果 ref 是用来引用页面上 DOM 元素的，那么初始值要给一个 null
        const ipt = ref(null)

        const getFocus = () => {
          // console.dir(ipt.value)
          ipt.value.focus()
        }

        return {
          ipt,
          getFocus
        }
      }
    })

    app.mount('#app')
  </script>
</head>

<body>
  <div id="app">
    <button @click="getFocus">让 input 获取焦点</button>
    <input type="text" ref="ipt">
  </div>
</body>

</html>